package org.hbrs.ooka;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.hbrs.ooka.model.Customer;
import org.hbrs.ooka.model.Product;
import org.hbrs.ooka.model.persistence.CustomerDAO;
import org.hbrs.ooka.model.persistence.CustomerDatabaseDAO;
import org.hbrs.ooka.model.persistence.DatabaseSource;
import org.hbrs.ooka.model.persistence.ProductDAO;
import org.hbrs.ooka.model.persistence.ProductDatabaseDAO;

public class TestClient {

	public static void main(String[] args) {
		DatabaseSource dbs = null;
		try {
			dbs = new DatabaseSource();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		CustomerDAO cdao = new CustomerDatabaseDAO(dbs);
		ProductDAO pdao = new ProductDatabaseDAO(dbs);
		
		List<Product> products = new ArrayList<>();
		products.add(new Product("Roten Teppich"));
		products.add(new Product("Zigarren"));
		
		Customer a = new Customer("Will", "Kommen", "Dingenskirchen", cdao, pdao);
		a.addProduct(products.get(0));
		a.addProduct(products.get(1));
		cdao.insertCustomer(a);
		
		System.out.println("Initial: ");
		System.out.println(a);
		
		
		a.rename("Hamburger");
		a.moveHome("Hamburg");
		a.removeProduct(products.get(0));
		
		System.out.println("Aenderungen: ");
		System.out.println(a);
		
		cdao.removeCustomer(a);
		
		System.out.println("Alles in der DB: ");
		for(Customer c : cdao.findAllCustomers())
			System.out.println(c);
		dbs.closeConnection();
	}

}
